#include "string.h"
#include<iostream>
using namespace yiwei;
using std::cout;
using std::cin;
using std::endl;



void test_string1() {
	string s1;
	string s2("hello");

	for (size_t i = 0; i < s1.size(); i++) {
		s1[i] += 1;
		cout << s1[i] << " ";
	}
	cout << std::endl;
	for (size_t i = 0; i < s2.size(); i++) {
		s2[i] += 1;
		cout << s2[i] << " ";
	}
	cout << std::endl;
}

void test_string2()
{
	string s1("hello");
	string s2(s1);
	string s3;
	s3 = s1;
	cout << s1 << " " << s1.size() << " " << s1.capacity() << endl;
	cout << s2 << " " << s2.size() << " " << s2.capacity() << endl;
	cout << s3 << " " << s3.size() << " " << s3.capacity() << endl;
}

void test_string3()
{
	string s1("hello");
	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		*it += 1;
		cout << *it << " ";
		++it;
	}
	cout << endl;
	for (auto& e : s1)
	{
		e -= 1;
		cout << e << " ";
	}
	cout << endl;
}

void test_string4()
{
	const string s1("hello");
	cout << s1.size() << " " << s1.capacity() << endl;

	for (size_t i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << " ";

	}
	cout << endl;
}

void test_string5()
{
	string s2;
	cin >> s2;
	cout << s2 << endl;
}

void test_string6()
{
	string s1("hello");

	s1.push_back(' ');
	s1.push_back('w');
	s1.push_back('o');
	s1.push_back('l');
	s1.push_back('r');
	s1.push_back('d');

	s1.append(" sdlkfhas");
	cout << s1 << endl;

}

void test_string7()
{
	string s1("hello");
	s1.insert(0, " world");
	cout << s1 << endl;
	cout << s1.size() << endl;

	s1.insert(0, 'h');
	cout << s1 << endl;

	s1.insert(2, " world ");
	cout << s1 << endl << endl;


	string s2("hello");
	s2.reserve(10);
	cout << s2 << " " << s2.size() << " " << s2.capacity() << endl;

	s2.resize(8, 'e');
	cout << s2 << " " << s2.size() << " " << s2.capacity() << endl;


	s2.resize(18, 'a');
	cout << s2 << " " << s2.size() << " " << s2.capacity() << endl;

	s2.resize(1);
	cout << s2 << " " << s2.size() << " " << s2.capacity() << endl;
}

int main() {

	test_string1();
	test_string2();
	test_string3();
	test_string4();
	test_string5();
	test_string6();
	test_string7();

	return 0;
}